home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 5 < prev    next >
Internet Message Format  |  1996-08-06  |  3KB

  1. Path: lyra.csx.cam.ac.uk!nmm1
  2. From: nmm1@cus.cam.ac.uk (Nick Maclaren)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Circular buffering for FILEs?  Why not?
  5. Date: 2 Jan 1996 10:32:21 GMT
  6. Organization: University of Cambridge, England
  7. Message-ID: <4cb1jl$2gb@lyra.csx.cam.ac.uk>
  8. References: <4c9i65$3b6@segfault.monkeys.com> <4c9q8e$63i@access2.digex.net> <4ca1ik$ffa@engnews2.Eng.Sun.COM>
  9. NNTP-Posting-Host: ursa.cus.cam.ac.uk
  10.  
  11. In article <4ca1ik$ffa@engnews2.Eng.Sun.COM>, corbett@lupa.eng.sun.com (Robert Corbett) writes:
  12. |> In article <4c9q8e$63i@access2.digex.net>,
  13. |> John Cochran <jdc@access2.digex.net> wrote:
  14. |> >In article <4c9i65$3b6@segfault.monkeys.com>,
  15. |> >Ronald F. Guilmette <rfg@monkeys.com> wrote:
  16. |> >>I have a question about the traditional implementation of buffered FILEs.
  17. |> >>
  18. |> >>From this fact I deduce that traditional implementations of the entire
  19. |> >>stdio set of functions _do not_ treat FILE buffers as so-called ``circular
  20. |> >>buffers'' but rather treat them a mere linear buffers.
  21. |> >>
  22. |> >>My question is just this... Why?
  23. |> >Why bother?
  24. |> 
  25. |> "Why bother" is the correct answer.  The reasons given (which I have
  26. |> deleted) are correct, but not complete.  A higher-level explanation
  27. |> might prove helpful.  Circular buffering is useful when I/O and
  28. |> processing can be overlapped.  Circular buffering allows sequential I/O
  29. |> to read ahead or write behind while the data already read is being
  30. |> processed or the next batch of data to be written is being computed.
  31. |> Since C has no notion of overlapped I/O and processing, circular
  32. |> buffering not useful in implementing the C I/O library.  The underlying
  33. |> OS might support overlapped I/O and processing.  The OS, therefore,
  34. |> might well be using circular buffers when dealing with sequential
  35. |> devices.  For direct access devices, the popular buffering schemes
  36. |> tend to be more complex than circular buffering.
  37.  
  38. This isn't quite complete, either!  "Since C has no notion of overlapped
  39. I/O and processing, ..." is true but misleading.
  40.  
  41. If the operating system uses C's buffers and buffer pointers directly
  42. (e.g. by the use of volatile, hardware interrupts on flagged values etc.),
  43. then it might well be worth using circular buffers.  But this is a very
  44. 1960s way of implementing I/O and is not, as far as I know, done by any
  45. existing system.
  46.  
  47.  
  48. Nick Maclaren,
  49. University of Cambridge Computer Laboratory,
  50. New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
  51. Email:  nmm1@cam.ac.uk
  52. Tel.:  +44 1223 334761    Fax:  +44 1223 334679
  53.